/*     */ package com.cr.generator.controller;
/*     */ 
/*     */ import com.alibaba.fastjson.JSON;
/*     */ import com.cr.common.annotation.Log;
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.core.domain.CxSelect;
/*     */ import com.cr.common.core.page.TableDataInfo;
/*     */ import com.cr.common.core.text.Convert;
/*     */ import com.cr.common.enums.BusinessType;
/*     */ import com.cr.common.utils.MyStringUtils;
/*     */ import com.cr.common.utils.security.PermissionUtils;
/*     */ import com.cr.generator.domain.GenTable;
/*     */ import com.cr.generator.domain.GenTableColumn;
/*     */ import com.cr.generator.service.IGenTableColumnService;
/*     */ import com.cr.generator.service.IGenTableService;
/*     */ import java.io.IOException;
/*     */ import java.io.OutputStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.io.IOUtils;
/*     */ import org.apache.shiro.authz.annotation.RequiresPermissions;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.ModelMap;
/*     */ import org.springframework.validation.annotation.Validated;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/tool/gen"})
/*     */ public class GenController extends BaseController {
/*  43 */   private String prefix = "tool/gen";
/*     */   
/*     */   @Autowired
/*     */   private IGenTableService genTableService;
/*     */   
/*     */   @Autowired
/*     */   private IGenTableColumnService genTableColumnService;
/*     */   
/*     */   @RequiresPermissions({"tool:gen:view"})
/*     */   @GetMapping
/*     */   public String gen() {
/*  55 */     return this.prefix + "/gen";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:list"})
/*     */   @PostMapping({"/list"})
/*     */   @ResponseBody
/*     */   public TableDataInfo genList(GenTable genTable) {
/*  66 */     startPage();
/*  67 */     List<GenTable> list = this.genTableService.selectGenTableList(genTable);
/*  68 */     return getDataTable(list);
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:list"})
/*     */   @PostMapping({"/db/list"})
/*     */   @ResponseBody
/*     */   public TableDataInfo dataList(GenTable genTable) {
/*  79 */     startPage();
/*  80 */     List<GenTable> list = this.genTableService.selectDbTableList(genTable);
/*  81 */     return getDataTable(list);
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:list"})
/*     */   @PostMapping({"/column/list"})
/*     */   @ResponseBody
/*     */   public TableDataInfo columnList(GenTableColumn genTableColumn) {
/*  92 */     TableDataInfo dataInfo = new TableDataInfo();
/*  93 */     List<GenTableColumn> list = this.genTableColumnService.selectGenTableColumnListByTableId(genTableColumn);
/*  94 */     dataInfo.setRows(list);
/*  95 */     dataInfo.setTotal(list.size());
/*  96 */     return dataInfo;
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:list"})
/*     */   @GetMapping({"/importTable"})
/*     */   public String importTable() {
/* 106 */     return this.prefix + "/importTable";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:list"})
/*     */   @Log(title = "代码生成", businessType = BusinessType.IMPORT)
/*     */   @PostMapping({"/importTable"})
/*     */   @ResponseBody
/*     */   public AjaxResult importTableSave(String tables) {
/* 118 */     String[] tableNames = Convert.toStrArray(tables);
/* 120 */     List<GenTable> tableList = this.genTableService.selectDbTableListByNames(tableNames);
/* 121 */     String operName = (String)PermissionUtils.getPrincipalProperty("loginName");
/* 122 */     this.genTableService.importGenTable(tableList, operName);
/* 123 */     return AjaxResult.success();
/*     */   }
/*     */   
/*     */   @GetMapping({"/edit/{tableId}"})
/*     */   public String edit(@PathVariable("tableId") Long tableId, ModelMap mmap) {
/* 132 */     GenTable table = this.genTableService.selectGenTableById(tableId);
/* 133 */     List<GenTable> genTables = this.genTableService.selectGenTableAll();
/* 134 */     List<CxSelect> cxSelect = new ArrayList<>();
/* 135 */     for (GenTable genTable : genTables) {
/* 137 */       if (!MyStringUtils.equals(table.getTableName(), genTable.getTableName())) {
/* 139 */         CxSelect cxTable = new CxSelect(genTable.getTableName(), genTable.getTableName() + '：' + genTable.getTableComment());
/* 140 */         List<CxSelect> cxColumns = new ArrayList<>();
/* 141 */         for (GenTableColumn tableColumn : genTable.getColumns())
/* 143 */           cxColumns.add(new CxSelect(tableColumn.getColumnName(), tableColumn.getColumnName() + '：' + tableColumn.getColumnComment())); 
/* 145 */         cxTable.setS(cxColumns);
/* 146 */         cxSelect.add(cxTable);
/*     */       } 
/*     */     } 
/* 149 */     mmap.put("table", table);
/* 150 */     mmap.put("data", JSON.toJSON(cxSelect));
/* 151 */     return this.prefix + "/edit";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:edit"})
/*     */   @Log(title = "代码生成", businessType = BusinessType.UPDATE)
/*     */   @PostMapping({"/edit"})
/*     */   @ResponseBody
/*     */   public AjaxResult editSave(@Validated GenTable genTable) {
/* 163 */     this.genTableService.validateEdit(genTable);
/* 164 */     this.genTableService.updateGenTable(genTable);
/* 165 */     return AjaxResult.success();
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:remove"})
/*     */   @Log(title = "代码生成", businessType = BusinessType.DELETE)
/*     */   @PostMapping({"/remove"})
/*     */   @ResponseBody
/*     */   public AjaxResult remove(String ids) {
/* 174 */     this.genTableService.deleteGenTableByIds(ids);
/* 175 */     return AjaxResult.success();
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:preview"})
/*     */   @GetMapping({"/preview/{tableId}"})
/*     */   @ResponseBody
/*     */   public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException {
/* 186 */     Map<String, String> dataMap = this.genTableService.previewCode(tableId);
/* 187 */     return AjaxResult.success(dataMap);
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:code"})
/*     */   @Log(title = "代码生成", businessType = BusinessType.GENCODE)
/*     */   @GetMapping({"/download/{tableName}"})
/*     */   public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
/* 198 */     byte[] data = this.genTableService.downloadCode(tableName);
/* 199 */     genCode(response, data);
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:code"})
/*     */   @Log(title = "代码生成", businessType = BusinessType.GENCODE)
/*     */   @GetMapping({"/genCode/{tableName}"})
/*     */   @ResponseBody
/*     */   public AjaxResult genCode(@PathVariable("tableName") String tableName) {
/* 211 */     this.genTableService.generatorCode(tableName);
/* 212 */     return AjaxResult.success();
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:edit"})
/*     */   @Log(title = "代码生成", businessType = BusinessType.UPDATE)
/*     */   @GetMapping({"/synchDb/{tableName}"})
/*     */   @ResponseBody
/*     */   public AjaxResult synchDb(@PathVariable("tableName") String tableName) {
/* 224 */     this.genTableService.synchDb(tableName);
/* 225 */     return AjaxResult.success();
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"tool:gen:code"})
/*     */   @Log(title = "代码生成", businessType = BusinessType.GENCODE)
/*     */   @GetMapping({"/batchGenCode"})
/*     */   @ResponseBody
/*     */   public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
/* 237 */     String[] tableNames = Convert.toStrArray(tables);
/* 238 */     byte[] data = this.genTableService.downloadCode(tableNames);
/* 239 */     genCode(response, data);
/*     */   }
/*     */   
/*     */   private void genCode(HttpServletResponse response, byte[] data) throws IOException {
/* 247 */     response.reset();
/* 248 */     response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
/* 249 */     response.addHeader("Content-Length", "" + data.length);
/* 250 */     response.setContentType("application/octet-stream; charset=UTF-8");
/* 251 */     IOUtils.write(data, (OutputStream)response.getOutputStream());
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-generator-4.7.0.jar!\com\cr\generator\controller\GenController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */